package com.uu.safeguard.service.impl;

import com.uu.safeguard.common.Constant;
import com.uu.safeguard.dao.StationDao;
import com.uu.safeguard.entity.Station;
import com.uu.safeguard.service.StationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * (Station)表服务实现类
 *
 * @author makejava
 * @since 2021-04-05 10:55:07
 */
@Service("stationService")
public class StationServiceImpl implements StationService {
    @Resource
    private StationDao stationDao;
    /**
     * @Description: 通过插座编号查询设备运营商
     * @Param: [sn]
     **/
    @Override
    public LinkedHashMap<String, String> findOperatorBySocketSn(String sn) {
        return stationDao.findOperatorBySocketSn(sn);
    }

    /**
     * @Description: 解绑设备
     * @Param: [stationSn]
     **/
    @Override
    public int stationRemove(String stationSn) {
        return stationDao.stationRemove(stationSn);
    }

    /**
     * @Description: 一键安装或解绑
     * @Param: [platformSn, operatorMemberSn, projectSn, stationSn]
     **/
    @Override
    public int updateStationByCondition(String platformSn, String operatorMemberSn, int projectSn, String stationSn,String stationName) {
        return stationDao.updateStationByCondition(platformSn,operatorMemberSn,projectSn,stationSn,stationName);
    }

    /**
     * @Description: 查询某小区在线设备详情
     * @Param: [sn]
     * @Author: cmt
     **/
    @Override
    public List<Map<String, String>> findProjectStationOnline(String sn) {
        return stationDao.findProjectStationOnline(sn,Constant.STATION_ONLINE_JUDGE);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param sn 主键
     * @return 实例对象
     */
    @Override
    public Station queryById(String sn) {
        return this.stationDao.queryById(sn);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Station> queryAllByLimit(int offset, int limit) {
        return this.stationDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param station 实例对象
     * @return 实例对象
     */
    @Override
    public Station insert(Station station) {
        this.stationDao.insert(station);
        return station;
    }

    /**
     * 修改数据
     *
     * @param station 实例对象
     * @return 实例对象
     */
    @Override
    public Station update(Station station) {
        this.stationDao.update(station);
        return this.queryById(station.getSn());
    }

    /**
     * 通过主键删除数据
     *
     * @param sn 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String sn) {
        return this.stationDao.deleteById(sn) > 0;
    }
    /**
     * @Description: 查询运营商在线及离线，总设备
     * @Param: [sn]
     * @Return: java.util.Map<java.lang.String,java.lang.String>
     * @Author: cmt
     * @Date: 2021/4/5 15:20
     **/
    @Override
    public Map<String, String> findOperatorAllStation(String sn) {
        return stationDao.findOperatorAllStation(sn, Constant.STATION_ONLINE_JUDGE);
    }
    /**
     * @Description: 查找运营商所有小区设备 在线 离线 插座 占用
     * @Param: [sn]
     * @Return: java.util.Map<java.lang.String,java.lang.String>
     * @Author: cmt
     * @Date: 2021/4/5 15:20
     **/
    @Override
    public List<Map<String, String>> findOperatorProjectDetails(String sn) {
        return stationDao.findOperatorProjectDetails(sn, Constant.STATION_ONLINE_JUDGE);
    }
}